use strict;
use warnings;

use Benchmark ':hireswallclock';
use YAML::Syck;

sub yaml_bench {
    my $filename = shift;
    my @y = YAML::Syck::LoadFile($filename);
    return scalar @y;
}

my ($filename, $n) = ($ARGV[0], int($ARGV[1]));
my $count = 0;
my $t = timeit($n, sub {
    $count += yaml_bench($filename);
});

print YAML::Syck::Dump({
    "perl/syck" => {
        "benchmark_script" => __FILE__,
        "language" => "perl",
        "interpreter" => {
            "name" => "perl",
            "version" => sprintf("%vd", $^V),
            "banner" => [split(/\n/, `perl -v`)]->[1],
        },
        "library" => {
            "name" => "YAML::Syck",
            "version" => $YAML::Syck::VERSION,
            "language" => ["C"],
            "native_library" => {
                "name" => "syck",
                "version" => "0.61",  # from syck.h
            },
        },
        "result" => {
            $filename => {
                "loaded" => $count,
                "wallclock" => $t->real,
            }
        }
    }
});
